//
//  DGGDarkAdapter.m
//  DGGMerchant
//
//  Created by 董文涛 on 2020/4/13.
//  Copyright © 2020 DGG. All rights reserved.
//

#import "DLThemeAdapter.h"
#import "DLGradientTool.h"
#import "UIColor+Color.h"
#import "DLColorDefin.h"

@implementation DLThemeAdapter


+ (instancetype)shareInstance
{
    static DLThemeAdapter *adapter = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        adapter = [[DLThemeAdapter alloc]init];
    });
    return adapter;
}


- (NSInteger)isDark
{
    #ifdef __IPHONE_13_0
        if (@available(iOS 13.0, *)) {
            return UITraitCollection.currentTraitCollection.userInterfaceStyle == UIUserInterfaceStyleDark;
        } else {
            return 0;
        }
    #else
        return 0;
    #endif
        return 0;
}

- (UIColor *)dgg_colorName:(NSString *)colorName
{
    return [UIColor dgg_colorNamed:colorName];
}


- (UIColor *)dynamicColor:(UIColor *)lightColor darkColor:(UIColor *)darkColor
{
#ifdef __IPHONE_13_0
    if (@available(iOS 13.0, *)) {
        UIColor *dyColor = [UIColor colorWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * _Nonnull traitCollection) {
            return traitCollection.userInterfaceStyle == UIUserInterfaceStyleLight ? lightColor : darkColor;
        }];
        return dyColor;
    } else {
        return lightColor;
    }
#else
    return lightColor;
#endif
    return lightColor;
}

+ (UIColor *)dynamicLc:(NSString *)lcString
                    dc:(NSString *)dcString
{
    return [[DLThemeAdapter shareInstance] dynamicColor:[UIColor colorWithHexString:lcString]
                                               darkColor:[UIColor colorWithHexString:dcString]];
}


- (UIImage *)dynamicImage:(NSArray<UIColor *> *)lightColors darkColors:(NSArray<UIColor *> *)darkColors size:(CGSize)size
{
    UIImage *lightImage = [DLGradientTool gradientImageWithColors:lightColors size:size];
    UIImage *darkImage = [DLGradientTool gradientImageWithColors:darkColors size:size];

    #ifdef __IPHONE_13_0
        if (@available(iOS 13.0, *)) {
            UITraitCollection *trait = [UITraitCollection currentTraitCollection];
            return trait.userInterfaceStyle == UIUserInterfaceStyleLight ? lightImage : darkImage;
        } else {
            return lightImage;
        }
    #else
        return lightImage;
    #endif
        return lightImage;
}


- (UIImage *)dynamicImage:(UIImage *)lightImage darkImage:(UIImage *)darkImage
{
#ifdef __IPHONE_13_0
    if (@available(iOS 13.0, *)) {
        UITraitCollection *trait = [UITraitCollection currentTraitCollection];
        return trait.userInterfaceStyle == UIUserInterfaceStyleLight ? lightImage : darkImage;
    } else {
        return lightImage;
    }
#else
    return lightImage;
#endif
    return lightImage;
}


+ (UIImage *)grapOrangeImage
{
    return [[DLThemeAdapter shareInstance] dynamicImage:@[DGG_RGB(255, 184, 61), DGG_RGB(255, 111, 0)]
                                              darkColors:@[DGG_RGB(255, 139, 51), DGG_RGB(233, 161, 63)]
                                                    size:CGSizeMake(62, 26)];
}

+ (UIImage *)grapUnableOrangeImage
{
    return [[DLThemeAdapter shareInstance] dynamicImage:@[DGG_RGB(255, 198, 154), DGG_RGB(255, 226, 177)]
                                              darkColors:@[DGG_RGB(75, 76, 77), DGG_RGB(75, 76, 77)]
                                                    size:CGSizeMake(62, 26)];
}


+ (UIColor *)themeColor
{
    return [[DLThemeAdapter shareInstance] dynamicColor:DGG_LC_THEME darkColor:DGG_DC_THEME];
}

+ (UIColor *)themeUnableColor
{
    return [[DLThemeAdapter shareInstance] dynamicColor:DGG_LC_THEME_UNABLE darkColor:DGG_DC_THEME_UNABLE];
}


+ (UIColor *)backgroundColor
{
    return [[DLThemeAdapter shareInstance] dynamicColor:DGG_LC_BACKGROUND darkColor:DGG_DC_BACKGROUND];
}

+ (UIColor *)backgroundColor2
{
    return [[DLThemeAdapter shareInstance] dynamicColor:[UIColor whiteColor] darkColor:DGG_DC_BACKGROUND];
}


+ (UIColor *)searchBackColor
{
    return [[DLThemeAdapter shareInstance] dynamicColor:DGG_LC_BACKGROUND darkColor:DGG_DC_3C3C3D];
}


+ (UIColor *)placeholderColor
{
    return [[DLThemeAdapter shareInstance] dynamicColor:DGG_LC_9398A1 darkColor:DGG_DC_868686];
}


+ (UIColor *)tabBarColor
{
    return [[DLThemeAdapter shareInstance] dynamicColor:[UIColor whiteColor] darkColor:DGG_DC_232323];
}


+ (UIColor *)navTintColor
{
    return [[DLThemeAdapter shareInstance] dynamicColor:DGG_LC_333333 darkColor:DGG_DC_E0E0E0];
}


+ (UIColor *)textBlackColor
{
    return [[DLThemeAdapter shareInstance] dynamicColor:DGG_LC_333333 darkColor:DGG_DC_E0E0E0];
}


+ (UIColor *)lineColor
{
    return [[DLThemeAdapter shareInstance] dynamicColor:DGG_LC_EEEEEE darkColor:DGG_DC_3C3C3D];
}


+ (UIColor *)lightBlackColor
{
    return [[DLThemeAdapter shareInstance] dynamicColor:DGG_LC_666666 darkColor:DGG_DC_AAAAAA];
}


+ (UIColor *)grayColor
{
    return [[DLThemeAdapter shareInstance] dynamicColor:DGG_LC_999999 darkColor:DGG_DC_868686];
}


+ (UIColor *)orangeColor
{
    return [[DLThemeAdapter shareInstance] dynamicColor:DGG_LC_FF8D29 darkColor:DGG_DC_FF8B33];
}

+ (UIColor *)redColor
{
    return [[DLThemeAdapter shareInstance] dynamicColor:DGG_LC_F24040 darkColor:DGG_DC_FF4545];
}


+ (UIColor *)cellBgColor
{
    return [[DLThemeAdapter shareInstance] dynamicColor:[UIColor whiteColor] darkColor:DGG_DC_1E1E1F];
}


+ (UIColor *)timeTextColor
{
    return [[DLThemeAdapter shareInstance] dynamicColor:DGG_LC_CCB495 darkColor:DGG_DC_AE9B83];
}


+ (UIColor *)timeBorderColor
{
    return [[DLThemeAdapter shareInstance] dynamicColor:DGG_LC_F5EFE6 darkColor:DGG_DC_3B3B3E];
}


+ (UIColor *)timeBgColor
{
    return [[DLThemeAdapter shareInstance] dynamicColor:[UIColor whiteColor] darkColor:DGG_DC_3B3B3E];
}


+ (UIColor *)copyTextColor
{
    return [[DLThemeAdapter shareInstance] dynamicColor:DGG_LC_333333 darkColor:DGG_DC_E0E0E0];
}


/// 复制按钮背景颜色
+ (UIColor *)copyBgColor
{
    return [[DLThemeAdapter shareInstance] dynamicColor:DGG_LC_F0F1F5 darkColor:DGG_DC_5A5B5B];
}


+ (UIColor *)grayBorderColor
{
    return [[DLThemeAdapter shareInstance] dynamicColor:DGG_LC_C5C9D4 darkColor:DGG_DC_696A6B];
}


+ (UIColor *)filtBackColor
{
    return [[DLThemeAdapter shareInstance] dynamicColor:[UIColor whiteColor] darkColor:DGG_DC_2D2D2E];
}


+ (UIColor *)filtCancelLayerColor
{
    return [[DLThemeAdapter shareInstance] dynamicColor:DGG_LC_D9D9D9 darkColor:DGG_DC_5A5B5B];
}


+ (UIColor *)filtItemBackColor
{
    return [[DLThemeAdapter shareInstance] dynamicColor:DGG_LC_F5F6F8 darkColor:DGG_DC_4B4C4D];
}


+ (UIColor *)filtItemSelectedBackColor
{
    return [[DLThemeAdapter shareInstance] dynamicColor:DGG_LC_C5EFEE darkColor:DGG_DC_385857];
}


+ (UIColor *)timeRunColor
{
    return [[DLThemeAdapter shareInstance] dynamicColor:DGG_DC_AAAAAA darkColor:DGG_DC_636363];
}

+ (UIColor *)textFieldBackColor
{
    return [[DLThemeAdapter shareInstance] dynamicColor:DGG_LC_F5F7FA darkColor:DGG_DC_3C3C3D];
}


@end
